<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>爬取信息管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <!--搜索开始-->
        <fieldset class="layui-elem-field layuimini-search">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="" id="searchFrm">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">书名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="bookName" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">作者</label>
                            <div class="layui-input-inline">
                                <input type="text" name="author" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">收录状态</label>
                            <div class="layui-input-inline">
                                <select name="downloadStatus" lay-filter="downloadStatus">
                                    <option value=""></option>
                                    <option value="0">未收录</option>
                                    <option value="1">已收录</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">开始时间</label>
                            <div class="layui-input-inline">
                                <input type="text" name="startTime" id="startTime" readonly="readonly"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">结束时间</label>
                            <div class="layui-input-inline">
                                <input type="text" name="endTime" id="endTime" readonly="readonly" autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-block" style="text-align: center;">
                            <a class="layui-btn " lay-submit="" lay-filter="data-search-btn"><label
                                    class="layui-icon layui-icon-search"></label>搜索</a>
                            <a class="layui-btn layui-btn-warm" onclick="javascript:$('#searchFrm')[0].reset()"
                               lay-filter="data-search-btn"><label class="layui-icon layui-icon-refresh"></label>重置</a>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <!--搜索结束-->

        <!--表格开始-->
        <table class="layui-hide" id="crawlerBookTable" lay-filter="crawlerBookTable"></table>
        <script type="text/html" id="crawlerBookToolBar">
            <a class="layui-btn layui-btn-sm layui-btn-danger data-count-delete" lay-event="batchinclude">批量收录</a>
        </script>
        <script type="text/html" id="crawlerBookTableBar">
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="include">收录</a>
            <a class="layui-btn layui-btn-xs layui-btn-warm data-count-delete" lay-event="show">查看简介</a>
        </script>
        <!--表格结束-->

        <!--添加和修改的弹出层开始-->
        <div id="addOrUpdateDiv" style="display: none;padding: 0.3125rem">
            <form method="post" class="layui-form layui-form-pane" lay-filter="dataFrm" id="dataFrm">
                <div class="layui-form-item">
                    <label class="layui-form-label">标题</label>
                    <div class="layui-input-block">
                        <input type="hidden" name="id"/>
                        <input type="text" name="title" lay-verify="required" autocomplete="off" placeholder="请输入标题"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">公告内容</label>
                    <div class="layui-input-block">
                        <div id="content" name="content" style="margin: 50px 0 50px 0">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block" style="text-align: center;">
                        <a class="layui-btn " lay-submit="" lay-filter="doSubmit"><label
                                class="layui-icon layui-icon-release"></label>提交</a>
                        <a class="layui-btn layui-btn-warm" onclick="javascript:$('#dataFrm')[0].reset()"
                           lay-filter="data-search-btn"><label class="layui-icon layui-icon-refresh"></label>重置</a>
                    </div>
                </div>
            </form>
        </div>
        <!--添加和修改的弹出层结束-->
    </div>
</div>

<script src="../../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="../../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="../../../lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>
<script src="../../../lib/common/jquery.cookie.min.js" charset="utf-8"></script>
<script src="../../../lib/common/common.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table', 'laydate', 'layer', 'wangEditor'], function () {
        var form = layui.form;
        var table = layui.table;
        var laydate = layui.laydate;
        var layer = layui.layer;
        var wangEditor = layui.wangEditor;

        //渲染时间选择器
        laydate.render({
            elem: '#startTime',
            type: 'datetime'
        });
        laydate.render({
            elem: '#endTime',
            type: 'datetime'
        });

        var tableIns = table.render({
            elem: '#crawlerBookTable',
            url: api + 'crawlerBook/loadAllCrawlerBook',
            toolbar: "#crawlerBookToolBar",
            cellMinWidth: true,
            cols: [[
                {type: "checkbox", fixed: "left"},
                {field: 'id', title: 'ID', align: "center"},
                {field: 'bookName', title: '书名', align: "center"},
                {field: 'author', title: '作者', align: "center"},
                {
                    field: 'primaryClassification', title: '一级分类', align: "center", templet: function (d) {
                        var classificationName = "";
                        switch (d.primaryClassification) {
                            case 1:
                                classificationName = "都市·娱乐";
                                break;
                            case 2:
                                classificationName = "武侠·仙侠";
                                break;
                            case 3:
                                classificationName = "奇幻·玄幻";
                                break;
                            case 4:
                                classificationName = "科幻·灵异";
                                break;
                            case 5:
                                classificationName = "历史·军事";
                                break;
                            case 6:
                                classificationName = "竞技·游戏";
                                break;
                            case 7:
                                classificationName = "二次元";
                                break;
                            default:
                                break;
                        }
                        return classificationName;
                    }
                },
                {
                    field: 'secondaryClassification', title: '二级分类', align: "center", templet: function (d) {
                        var classificationName = "";
                        switch (d.secondaryClassification) {
                            case 1:
                                classificationName = "都市·娱乐";
                                break;
                            case 7:
                                classificationName = "二次元";
                                break;
                            case 8:
                                classificationName = "精校武侠";
                                break;
                            case 9:
                                classificationName = "精校仙侠";
                                break;
                            case 10:
                                classificationName = "精校奇幻";
                                break;
                            case 11:
                                classificationName = "精校玄幻";
                                break;
                            case 12:
                                classificationName = "精校科幻";
                                break;
                            case 13:
                                classificationName = "精校灵异";
                                break;
                            case 14:
                                classificationName = "精校历史";
                                break;
                            case 15:
                                classificationName = "精校军事";
                                break;
                            case 16:
                                classificationName = "精校竞技";
                                break;
                            case 17:
                                classificationName = "精校游戏";
                                break;
                            default:
                                break;
                        }
                        return classificationName;
                    }
                },
                {field: 'tertiaryClassification', title: '三级分类', align: "center"},
                {field: 'saveTime', title: '保存时间', align: "center"},
                {field: 'downloadUrl', title: '下载地址', align: "center"},
                {
                    field: 'downloadStatus', title: '收录状态', align: "center", templet: function (d) {
                        return d.downloadStatus == 0 ? "未收录" : "已收录";
                    }
                },
                {title: '操作', templet: '#crawlerBookTableBar', fixed: "right", align: "center"}
            ]],
            page: true
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var params = $("#searchFrm").serialize();
            //执行搜索重载
            table.reload('crawlerBookTable', {
                page: {
                    curr: 1
                }
                , url: api + 'crawlerBook/loadAllCrawlerBook?' + params
            });
            return false;
        });

        //监听表头的事件
        table.on('toolbar(crawlerBookTable)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'batchinclude':
                    batchinclude();
                    break;
                case 'add':
                    openAddNotice();
                    break;
            }
            ;
        });

        //监听行数据的事件
        table.on('tool(crawlerBookTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'include') {
                layer.confirm('真的要收录这本小说么', function (index) {
                    layer.msg("收录过程时间稍长，收录完成后请到收录目录查看");
                    $.post(api + "crawlerBook/include", {id: data.id}, function (res) {

                    })
                    layer.close(index);
                });
            } else if (obj.event === 'update') {
                openUpdateNotice(data);
            } else if (obj.event === 'show') {
                showNotice(data);
            }
        });


        //提交数据
        form.on("submit(doSubmit)", function (data) {
            var params = $("#dataFrm").serialize();
            var content = editor.txt.html();
            params += "&content=" + content;
            $.post(url, params, function (res) {
                layer.msg(res.msg);
                if (res.code == 200) {
                    tableIns.reload();
                }
                layer.close(mainIndex);
            })
            return false;
        })


        //批量收录
        function batchinclude() {
            var checkStatus = table.checkStatus('crawlerBookTable'); //idTest 即为基础参数 id 对应的值
            var data = checkStatus.data;
            var length = checkStatus.data.length;
            console.log(checkStatus.data) //获取选中行的数据
            console.log(checkStatus.data.length) //获取选中行数量，可作为是否有选中行的条件
            if (length == 0) {
                layer.msg("请选中要收录的小说");
            } else {
                layer.confirm('真的收录选择中这些小说么?', function (index) {
                    var params = "";
                    $.each(data, function (index, item) {
                        if (index == 0) {
                            params += "ids=" + item.id;
                        } else {
                            params += "&ids=" + item.id;
                        }
                    });
                    layer.msg("收录过程时间稍长，收录完成后请到收录目录查看");
                    $.post(api + "crawlerBook/batchInclude", params, function (res) {
                    })
                    layer.close(index);
                });
            }
        }

        //查看简介
        function showNotice(data) {
            var title = data.bookName;
            var content = data.introduction;
            var crawlerBookTime = data.saveTime;
            var publisher = data.author;
            var html = '<div style="padding:15px 20px; text-align:justify; line-height: 22px;border-bottom:1px solid #e2e2e2;background-color: #2f4056;color: #ffffff">\n' +
                '<div style="text-align: center;margin-bottom: 20px;font-weight: bold;border-bottom:1px solid #718fb5;padding-bottom: 5px"><h4 class="text-danger">' + title + '</h4></div>\n' +
                '<div style="font-size: 12px">' + content + '</div>\n' +
                '</div>\n';
            parent.layer.open({
                type: 1,
                title: '系统公告' + '<span style="float: right;right: 1px;font-size: 12px;color: #b1b3b9;margin-top: 1px">发布时间:' + crawlerBookTime + ' 发布人:' + publisher + '</span>',
                area: '800px;',
                shade: 0.8,
                btn: ['关闭'],
                btnAlign: 'c',
                moveType: 1,
                content: html
            });
        }
    });
</script>

</body>
</html>